package com.example.demo.service;

import com.example.demo.model.LinkCategory;
import com.example.demo.repository.LinkCategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class LinkCategoryService {
    
    private final LinkCategoryRepository linkCategoryRepository;
    
    @Autowired
    public LinkCategoryService(LinkCategoryRepository linkCategoryRepository) {
        this.linkCategoryRepository = linkCategoryRepository;
    }
    
    /**
     * 获取所有网站链接分类
     */
    public List<LinkCategory> findAllLinkCategories() {
        return linkCategoryRepository.findByOrderByDisplayOrderAsc();
    }
    
    /**
     * 通过ID查找网站链接分类
     */
    public Optional<LinkCategory> findById(Long id) {
        return linkCategoryRepository.findById(id);
    }
    
    /**
     * 保存网站链接分类
     */
    public LinkCategory saveLinkCategory(LinkCategory category) {
        return linkCategoryRepository.save(category);
    }
    
    /**
     * 删除网站链接分类
     */
    public void deleteLinkCategory(Long id) {
        linkCategoryRepository.deleteById(id);
    }
    
    /**
     * 根据名称查找分类
     */
    public Optional<LinkCategory> findByName(String name) {
        return linkCategoryRepository.findByName(name);
    }
} 